package com.qiwo.webshow.controller;


import java.util.Arrays;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.qiwo.common.base.AdminBaseController;
import com.qiwo.webshow.domain.HomeImgDO;
import com.qiwo.webshow.service.HomeImgService;
import com.qiwo.common.utils.Result;

/**
 * 
 * <pre>
 * 首页地图
 *  @author  chenwenchao
 *  @date 2018-10-24 21:38:50
 * </pre>
 * <small> 2018-10-24 21:38:50 | chenwenchao</small>
 */
@Controller
@RequestMapping("/webshow/homeImg")
public class HomeImgController extends AdminBaseController {
	@Autowired
	private HomeImgService homeImgService;
	
	@GetMapping()
	@RequiresPermissions("webshow:homeImg:homeImg")
	String HomeImg(){
	    return "webshow/homeImg/homeImg";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("webshow:homeImg:homeImg")
	public Result<Page<HomeImgDO>> list(HomeImgDO homeImgDTO){
        Wrapper<HomeImgDO> wrapper = new EntityWrapper<HomeImgDO>().orderBy("id", false);
        Page<HomeImgDO> page = homeImgService.selectPage(getPage(HomeImgDO.class), wrapper);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("webshow:homeImg:add")
	String add(){
	    return "webshow/homeImg/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("webshow:homeImg:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		HomeImgDO homeImg = homeImgService.selectById(id);
		model.addAttribute("homeImg", homeImg);
	    return "webshow/homeImg/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("webshow:homeImg:add")
	public Result<String> save( HomeImgDO homeImg){
		homeImgService.insert(homeImg);
        return Result.ok();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("webshow:homeImg:edit")
	public Result<String>  update( HomeImgDO homeImg){
		boolean update = homeImgService.updateById(homeImg);
		return update ? Result.ok() : Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("webshow:homeImg:remove")
	public Result<String>  remove( Long id){
		homeImgService.deleteById(id);
        return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("webshow:homeImg:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] ids){
		homeImgService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
